package com.ihomey.linkuphome.adapter;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.ViewGroup;

import com.ihomey.linkuphome.R;
import com.ihomey.linkuphome.ui.ControlParentFragment;
import com.ihomey.linkuphome.ui.DeviceFragment;
import com.ihomey.linkuphome.ui.GroupParentFragment;

public class LightFragmentAdapter extends FragmentPagerAdapter {

    private int lightType;
    private int mTitles[] = {R.string.tab_control, R.string.tab_search_device, R.string.tab_group_setting};
    private Context mContext;

    public LightFragmentAdapter(Context context, FragmentManager fm, int lightType) {
        super(fm);
        this.mContext = context;
        this.lightType=lightType;
    }

    @Override
    public Fragment getItem(int position) {
        if (position == 0) {
            return ControlParentFragment.newInstance(lightType);
        } else if (position == 1) {
            return DeviceFragment.newInstance(lightType);
        } else {
            return GroupParentFragment.newInstance(lightType);
        }
    }

    @Override
    public int getCount() {
        return mTitles.length;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        int res = mTitles[position];
        return mContext.getResources().getString(res);
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
//        super.destroyItem(container, position, object);
    }
}
